package com.llh.designpatterns.singleton.lazy;

/**
 * <h2>懒汉单例</h2>
 * <p>使用了双重检查：保证线程安全，实现了延迟加载</p>
 * <p>实际中常用此法。（双重检查是多线程里的一个小技巧）</p>
 * <p>CreatedAt: 2019-11-23 20:35</p>
 * <p><a href="mailto:forever2y_y@163.com">SendMailToMe</a></p>
 *
 * @author llh
 */
class Singleton02 {
    private Singleton02() {
    }

    private static volatile Singleton02 instance;

    static Singleton02 getInstance() {
        if (null == instance) {
            synchronized (Singleton02.class) {
                if (null == instance)
                    instance = new Singleton02();
            }
        }
        return instance;
    }
}
